//
//  JWAddressBookViewController.m
//  jinwang
//
//  Created by jzb on 2018/2/24.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "JWAddressBookViewController.h"
#import "HWScanViewController.h"
#import "JWAddressBookContactsVC.h"
#import "JWAddressBookNewFriendsVC.h"

@interface JWAddressBookViewController ()

@property (nonatomic,strong) UIButton *SaoYiSaoBtn;

@property (nonatomic,strong) UISearchBar *homeSearch;//搜索框

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;

@end

@implementation JWAddressBookViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kRGBColor(245, 245, 245);
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    UIBarButtonItem *SaoYiSaoItem = [[UIBarButtonItem alloc]initWithCustomView:self.SaoYiSaoBtn];
    self.navigationItem.rightBarButtonItem = SaoYiSaoItem;
    
    [self.view addSubview:self.homeSearch];
    
    NSArray *list = @[@"联系人",@"新朋友"];
    
//    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRM(0, 64*2+54*2, 750, 90) titles:list headStyle:SegmentHeadStyleDefault layoutStyle:MLMSegmentLayoutDefault];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, 54, kScreenWidth, 44) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    _segHead.fontSize = 16;
    _segHead.deSelectColor = kRGBColor(80, 80, 80);
    _segHead.selectColor = UIColorHex(0xEEA72B);
    _segHead.lineScale = .6;
    _segHead.bottomLineHeight = 0;
    _segHead.lineColor = UIColorHex(0xEEA72B);
//    _segHead.bottomLineColor = kRGBColor(230, 230, 230);
    _segHead.moreButton_width = kScreenWidth/2;
    _segHead.backgroundColor = [UIColor whiteColor];
    //CGRM(0, 88+64*2+60*2, 750, 1334-88-64*2-49*2-60*2)
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, 44+54, kScreenWidth, kScreenHeight-64-49-54-44) vcOrViews:[self vcArr:list.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
    //    _segScroll.backgroundColor = [UIColor purpleColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];
}

#pragma mark -懒加载
- (UIButton *)SaoYiSaoBtn{
    if (!_SaoYiSaoBtn) {
        _SaoYiSaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _SaoYiSaoBtn.frame = CGRectMake(0, 0, 44, 44);
        [_SaoYiSaoBtn setImage:[UIImage imageNamed:@"jw_tongxunlu_sysIcon"] forState:UIControlStateNormal];
        [_SaoYiSaoBtn addTarget:self action:@selector(SaoYiSaoButOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _SaoYiSaoBtn;
}
#pragma mark 懒加载
//控件
-(UISearchBar *)homeSearch{
    if (!_homeSearch) {
        _homeSearch = [[UISearchBar alloc]initWithFrame:CGRectMake(7.5, 6, kScreenWidth-15, 44)];
        _homeSearch.placeholder = @"搜索";
        _homeSearch.tintColor = UIColorHex(0xEEA72B);
        
        _homeSearch.searchBarStyle = UISearchBarStyleProminent;
        _homeSearch.barTintColor = kRGBColor(245, 245, 245);
        UIImageView *barImageView = [[[_homeSearch.subviews firstObject] subviews] firstObject];
        barImageView.layer.borderColor = kRGBAColor(248,248,248,1).CGColor;
        barImageView.layer.borderWidth = 1;
    }
    return _homeSearch;
}
- (void)SaoYiSaoButOnclick:(UIButton *)sender{
    
    HWScanViewController *vc = [HWScanViewController new];
    
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 数据源
- (NSArray *)vcArr:(NSInteger)count {
    NSMutableArray *arr = [NSMutableArray array];
    
    JWAddressBookContactsVC *Contacts_VC = [[JWAddressBookContactsVC alloc]init];
    JWAddressBookNewFriendsVC *NewFriends_VC = [[JWAddressBookNewFriendsVC alloc]init];
    
//    Contacts_VC.view.backgroundColor = [UIColor cyanColor];
//    NewFriends_VC.view.backgroundColor = [UIColor purpleColor];
    
    [arr addObject:Contacts_VC];
    [arr addObject:NewFriends_VC];
    
    return arr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
